Running openQmin (Python interface)
Running openQmin (Python interface)¶
Using tools/runHelper.py, you can define command-line parameters through a Python dictionary runHelper.params. These, along with any default parameters you didn’t change, are converted by runHelper.get_runcmd() into a command-line string that calls build/openQmin.out.
The dictionary keys of runHelper.params are the same as the long forms (appearing after the --s) of the command-line flags seen when you run build/openQmin.out --help, with the following exceptions:
helpitself is not a key inrunHelper.paramsParameters
'whole_Lx','whole_Ly', and'whole_Lz', which define the system size before subdivision over MPI ranks, override'Lx','Ly', and'Lz'by default. If you want to use'Lx','Ly','Lz'instead (which give the system size on each rank), you can passdo_partition=FalsetorunHelper.get_runcmd().
<<<<<<< HEAD
=======
--boxL(or-l) for specifying cubic box size is not used here to avoid ambiguity.
>>>>>>> documentation-recovery-3-justdocs
In the example below, we’ll make use of an example boundaryFile that we created in the page on Boundary conditions (Python interface) and the example initialConfigurationFiles that we created in the page on Initialization (Python interface).
Notice that the main openQmin directory path, assigned to runHelper.directory, is automatically prepended to the filepaths for imported and exported data. This directory path should be either an absolute path or relative to where you’ll be running the command.
import sys
sys.path.append("../../tools/") # path to runHelper.py
import runHelper
runHelper.directory = "~/open-Qmin/" # path to openQmin main directory
runHelper.mpi_num_processes = 3 # set to 1 for non-MPI run
=======
from sys import path
path.append("../tools/") # <-- replace with your path to runHelper.py
import runHelper
runHelper.directory = "../" # path to openQmin main directory
runHelper.mpi_num_processes = 4 # set to 1 for non-MPI run
>>>>>>> documentation-recovery-3-justdocs
runHelper.params["boundaryFile"] = "ceiling_and_wavy_floor.txt"
runHelper.params["initialConfigurationFile"] = "my_init_file"
# choose a location and filename-prefix for this run's results
runHelper.params["saveFile"] = "data/my_example_run"
runHelper.params["iterations"] = 500 # max number of minimization timesteps
# system size BEFORE subdivision across MPI ranks:
runHelper.params["whole_Lx"] = 50
runHelper.params["whole_Ly"] = 50
runHelper.params["whole_Lz"] = 50
runcmd = runHelper.get_runcmd() # generate command-line string
print(runcmd)
mpirun -n 3 ../build/openQmin.out --initializationSwitch 0 --GPU -1 --phaseConstantA 0.172 --phaseConstantB 2.12 --phaseConstantC 1.73 --deltaT 0.0005 --fTarget 1e-12 --iterations 500 --nConstants 1 --randomSeed -1 --L1 4.64 --L2 4.64 --L3 4.64 --L4 4.64 --L6 4.64 --boxL 50 --Lx 16 --Ly 50 --Lz 50 --initialConfigurationFile my_init_file --boundaryFile ceiling_and_wavy_floor.txt --saveFile data/my_example_run --linearSpacedSaving -1 --logSpacedSaving -1 --stride 1 --hFieldX 0 --hFieldY 0 --hFieldZ 0 --hFieldMu0 1 --hFieldChi 1 --hFieldDeltaChi 0.5 --eFieldX 0 --eFieldY 0 --eFieldZ 0 --eFieldEpsilon0 1 --eFieldEpsilon 1 --eFieldDeltaEpsilon 0.5
=======
mpirun -n 4 ../build/openQmin.out --initializationSwitch 0 --GPU -1 --phaseConstantA -0.172 --phaseConstantB -2.12 --phaseConstantC 1.73 --deltaT 0.0005 --fTarget 1e-12 --iterations 500 --randomSeed -1 --L1 4.64 --L2 4.64 --L3 4.64 --L4 4.64 --L6 4.64 --Lx 25 --Ly 25 --Lz 50 --initialConfigurationFile ../my_init_file --boundaryFile ../ceiling_and_wavy_floor.txt --saveFile ../data/my_example_run --linearSpacedSaving -1 --logSpacedSaving -1 --stride 1 --hFieldX 0 --hFieldY 0 --hFieldZ 0 --hFieldMu0 1 --hFieldChi 1 --hFieldDeltaChi 0.5 --eFieldX 0 --eFieldY 0 --eFieldZ 0 --eFieldEpsilon0 1 --eFieldEpsilon 1 --eFieldDeltaEpsilon 0.5
>>>>>>> documentation-recovery-3-justdocs
We can run openQmin with these options by any of the following routes:
Call
runHelper.run(), which executes the result ofrunHelper.get_runcmd()Copy and paste the string into a terminal
Use the
runcmdstring in a Python script viaimport os; os.system(runcmd)Run as shell command in a Jupyter notebook with
!{runcmd}
runHelper.run()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [2], in <module>
----> 1 runHelper.run()
AttributeError: module 'runHelper' has no attribute 'run'
Let’s take a look at the result using openViewMin.
# Install openViewMin dependencies as needed
!{sys.executable} -m pip install pandas "PyQt5<5.14" pyvistaqt tqdm imageio-ffmpeg >> /dev/null
=======
lattice divisions: {2, 2, 1}
loading state...
loading state...
loading state...
loading state...
reading file with 2objects
reading boudary type 0 with 5.300000 0.530000 and 26307 entries
reading file with 2objects
reading boudary type 0 with 5.300000 0.530000 and 26307 entries
reading file with 2objects
reading boudary type 0 with 5.300000 0.530000 and 26307 entries
reading file with 2objects
reading boudary type 0 with 5.300000 0.530000 and 26307 entries
object with 26307 sites created
there are now 1 boundary objects known to the configuration... last object had 6577 sites and 1898 surface sites
reading boudary type 1 with 5.300000 0.530000 and 2500 entries
object with 2500 sites created
there are now 2 boundary objects known to the configuration... last object had 625 sites and 725 surface sites
object with 26307 sites created
there are now 1 boundary objects known to the configuration... last object had 6576 sites and 1895 surface sites
reading boudary type 1 with 5.300000 0.530000 and 2500 entries
object with 2500 sites created
there are now 2 boundary objects known to the configuration... last object had 625 sites and 726 surface sites
object with 26307 sites created
there are now 1 boundary objects known to the configuration... last object had 6577 sites and 1898 surface sites
reading boudary type 1 with 5.300000 0.530000 and 2500 entries
object with 26307 sites created
there are now 1 boundary objects known to the configuration... last object had 6577 sites and 1898 surface sites
reading boudary type 1 with 5.300000 0.530000 and 2500 entries
object with 2500 sites created
there are now 2 boundary objects known to the configuration... last object had 625 sites and 725 surface sites
object with 2500 sites created
there are now 2 boundary objects known to the configuration... last object had 625 sites and 725 surface sites
fire finished: step 500 max force:3.91e-05 power: 2.36 alpha 0.99 dt 0.045125 scaling 0.249
fire finished: step 500 max force:3.91e-05 power: 2.36 alpha 0.99 dt 0.045125 scaling 0.249
fire finished: step 500 max force:3.91e-05 power: 2.36 alpha 0.99 dt 0.045125 scaling 0.249
fire finished: step 500 max force:3.91e-05 power: 2.36 alpha 0.99 dt 0.045125 scaling 0.249
-5236.936485 581.264815 69.360692 0.000000 0.000000
minimized to 3.91031e-05 E=-0.190661
-5236.933788 581.235202 69.360335 0.000000 0.000000
minimized to 3.91031e-05 E=-0.190661
-5237.066075 581.634041 74.221093 0.000000 0.000000
minimized to 3.91031e-05 E=-0.190661
-5236.937263 581.229330 69.360224 0.000000 0.000000
minimized to 3.91031e-05 E=-0.190661
>>>>>>> documentation-recovery-3-justdocs
# replace with your path to openViewMin:
sys.path.append("../../../openviewmin/")
=======
Let’s take a look at the result. Here we’re using openViewMin, a visualization environment under development for use with open-Qmin. This project is not yet publicly available, so if you want to help test it out, please contact Daniel Beller at d.a.beller [at] jhu.edu.
# NOTE: Running this cell requires using openViewMin's auto-generated Python environment "openViewMin-env" as the kernel for the Jupyter notebook.
path.append("../../openviewmin/") # <-- replace with your path to openViewMin
>>>>>>> documentation-recovery-3-justdocs
import openViewMin
import glob
# collect all files from this run
<<<<<<< HEAD
savedFiles = glob.glob("../../data/my_example_run*")
=======
savedFiles = glob.glob("../data/my_example_run*")
>>>>>>> documentation-recovery-3-justdocs
# generate plot off-screen
nplot = openViewMin.NematicPlot(savedFiles, off_screen=True, window_size=(800, 800))
# rotate plane of director glyphs to y-normal
nplot.update_filter("director_plane", {"normal":[0,1,0]}, update_self_actor=True)
# reduce lighting intensity a bit
nplot.set_lights_intensity(0.6)
# display in notebook
<<<<<<< HEAD
display(nplot.to_pythreejs())
=======
nplot_p3js = nplot.to_pythreejs()
>>>>>>> documentation-recovery-3-justdocs
nplot.close()
<<<<<<< HEAD
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-dbeller'
['../data/my_example_run_x0y1z0.txt', '../data/my_example_run_x1y0z0.txt', '../data/my_example_run_x1y1z0.txt', '../data/my_example_run_x0y0z0.txt'] -> ../data/my_example_run.txt
display(nplot_p3js)